<template>
	<view>
		<cu-custom bgColor="bg-orange" :isBack="true">
			<block slot="backText"></block>
			<block slot="content">修改资料</block>
		</cu-custom>
		<view class="avatarUrl">
			<button open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
				<image :src="userinfo.avatarUrl" class="refreshIcon"></image>
				<text>点击更换头像</text>
			</button>
		</view>
		<view class="userinfo">
			<view class="username" @click="changename">
				<text>昵称：{{userinfo.nickName}}</text>
				<uni-icons type="arrowright" size="15"></uni-icons>
			</view>
		</view>
	</view>
</template>

<script>
	// 以下路径需根据项目实际情况填写
	import {
		pathToBase64,
		base64ToPath
	} from '../../js_sdk/mmmm-image-tools/index.js'
	import {
		mapMutations,
		mapState
	} from 'vuex'
import { compile } from 'vue';
	export default {
		data() {
			return {
				img: [],
			};
		},
		computed: {
			...mapState('m_user', ['token', 'userinfo'])
		},
		methods: {
			...mapMutations('m_user', ['updateUserInfo']),
			//更换头像
			onChooseAvatar(e) {
				uni.uploadFile({
					url: 'http://10.12.28.130:1012/update/updateimage',
					filePath: e.detail.avatarUrl,
					name: 'file',
					formData: {
						token: this.token
					},
					success:(uploadres)=> {
						const data1=JSON.parse(uploadres.data)
						// console.log(data1.data)
						
						this.updateUserInfo({
							...this.userinfo,
							avatarUrl: data1.data
						});
						uni.showToast({
							title: '更新成功！',
							icon: 'success',
							duration: 1500
						});
					}
				})
			},
			//更换昵称
			changename() {
				uni.navigateTo({
					url: '/pages/changename/changename'
				})
			}
		}
	}
</script>

<style lang="less">
	.avatarUrl {
		padding: 80rpx 0 40rpx;
		background: #fff;

		button {
			background: #fff;
			line-height: 100rpx;
			height: auto;
			width: auto;
			padding: 20rpx 30rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			outline: none;
			font-size: 30rpx;
			color: #c9d6de;

			.refreshIcon {
				width: 160rpx;
				height: 160rpx;
				border-radius: 50%;
			}

			.jt {
				width: 14rpx;
				height: 28rpx;
			}
		}
	}

	// botton 去除边框
	button::after {
		border: none;
	}

	.userinfo {
		display: flex;
		justify-content: center;

		.username {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 645rpx;
			height: 150rpx;
			font-size: 15px;
			padding: 0 10px;
			line-height: 45px;
			background-color: #f8ecc9;
			border-radius: 35rpx;
			box-shadow: 0px 0px 24px -1px rgba(0, 0, 0, 0.1);
		}

	}
</style>